package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.plaf.*;
	import org.aswing.skinbuilder.SkinProgressBarBackground;
	import org.aswing.skinbuilder.SkinProgressBarForeground;
	
	public class FrameTask extends JFrame
	{
		//members define
		private var panel108:JPanel;
		private var panel109:JPanel;
		private var btn_task_accepted:JToggleButton;
		private var btn_task_acceptable:JToggleButton;
		private var panelItems:JPanel;
		private var labelGoalInfo:JLabel;
		private var txtGoal:JTextArea;
		private var panelReward:JPanel;
		private var labelRewardInfo:JLabel;
		private var labelEXP:JLabel;
		private var labelMoney:JLabel;
		private var labelWood:JLabel;
		private var labelFood:JLabel;
		private var panelItemsReward:JPanel;
		private var txtRecord:JTextArea;
		private var panel120:JPanel;
		private var btn_task_give_up:JButton;
		private var btn_task_complete:JButton;
		
		
		//-----------------------------------
		private var btn_close:JButton;
		public function FrameTask()
		{
			setResizable(false);
			setBackgroundDecorator(null);
			setBorder(new EmptyBorder());
			
			btn_close = new JButton();
			btn_close.setLocation(new IntPoint(198, -5));
			btn_close.setSize(new IntDimension(27, 27));
			btn_close.setPreferredSize(new IntDimension(27, 27));
			getTitleBar().setCloseButton(btn_close);
			getTitleBar().setMinimizeHeight(32);
			
			//component creation
			setSize(new IntDimension(420, 408));
			setPreferredSize(new IntDimension(420, 408));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			panel108 = new JPanel();
			panel108.setLocation(new IntPoint(0, 0));
			panel108.setSize(new IntDimension(420, 33));
			panel108.setPreferredSize(new IntDimension(420, 33));
			var layout1:FlowLayout = new FlowLayout();
			layout1.setAlignment(AsWingConstants.LEFT);
			layout1.setHgap(20);
			layout1.setVgap(4);
			layout1.setMargin(true);
			panel108.setLayout(layout1);
			
			panel109 = new JPanel();
			panel109.setLocation(new IntPoint(5, 5));
			panel109.setSize(new IntDimension(10, 10));
			panel109.setPreferredSize(new IntDimension(149, 25));
			var layout2:FlowWrapLayout = new FlowWrapLayout();
			layout2.setPreferWidth(200);
			layout2.setAlignment(AsWingConstants.CENTER);
			layout2.setHgap(3);
			layout2.setVgap(0);
			layout2.setMargin(false);
			panel109.setLayout(layout2);
			
			btn_task_accepted = new JToggleButton();
			btn_task_accepted.setLocation(new IntPoint(5, 5));
			btn_task_accepted.setSize(new IntDimension(73, 25));
			btn_task_accepted.setPreferredSize(new IntDimension(73, 25));
			btn_task_accepted.setText("label");
			
			btn_task_acceptable = new JToggleButton();
			btn_task_acceptable.setLocation(new IntPoint(5, 35));
			btn_task_acceptable.setSize(new IntDimension(73, 25));
			btn_task_acceptable.setPreferredSize(new IntDimension(73, 25));
			btn_task_acceptable.setText("label");
			
			panelItems = new JPanel();
			panelItems.setLocation(new IntPoint(8, 34));
			panelItems.setSize(new IntDimension(129, 306));
			panelItems.setPreferredSize(new IntDimension(129, 306));
			var layout3:FlowWrapLayout = new FlowWrapLayout();
			layout3.setPreferWidth(200);
			layout3.setAlignment(AsWingConstants.LEFT);
			layout3.setHgap(0);
			layout3.setVgap(0);
			layout3.setMargin(false);
			panelItems.setLayout(layout3);
			
			labelGoalInfo = new JLabel();
			labelGoalInfo.setLocation(new IntPoint(140, 34));
			labelGoalInfo.setSize(new IntDimension(271, 20));
			labelGoalInfo.setPreferredSize(new IntDimension(271, 20));
			labelGoalInfo.setText("任务说明");
			
			txtGoal = new JTextArea();
			txtGoal.setLocation(new IntPoint(140, 54));
			txtGoal.setSize(new IntDimension(271, 76));
			txtGoal.setPreferredSize(new IntDimension(271, 76));
			
			panelReward = new JPanel();
			panelReward.setLocation(new IntPoint(140, 130));
			panelReward.setSize(new IntDimension(271, 93));
			panelReward.setPreferredSize(new IntDimension(271, 93));
			var layout4:EmptyLayout = new EmptyLayout();
			panelReward.setLayout(layout4);
			
			labelRewardInfo = new JLabel();
			labelRewardInfo.setLocation(new IntPoint(0, 0));
			labelRewardInfo.setSize(new IntDimension(271, 20));
			labelRewardInfo.setPreferredSize(new IntDimension(271, 20));
			labelRewardInfo.setText("任务奖励");
			
			labelEXP = new JLabel();
			labelEXP.setLocation(new IntPoint(19, 23));
			labelEXP.setSize(new IntDimension(45, 16));
			labelEXP.setPreferredSize(new IntDimension(45, 16));
			labelEXP.setText("label");
			
			labelMoney = new JLabel();
			labelMoney.setLocation(new IntPoint(83, 23));
			labelMoney.setSize(new IntDimension(45, 16));
			labelMoney.setPreferredSize(new IntDimension(45, 16));
			labelMoney.setText("label");
			
			labelWood = new JLabel();
			labelWood.setLocation(new IntPoint(155, 23));
			labelWood.setSize(new IntDimension(45, 16));
			labelWood.setPreferredSize(new IntDimension(45, 16));
			labelWood.setText("label");
			
			labelFood = new JLabel();
			labelFood.setLocation(new IntPoint(220, 23));
			labelFood.setSize(new IntDimension(45, 16));
			labelFood.setPreferredSize(new IntDimension(45, 16));
			labelFood.setText("label");
			
			panelItemsReward = new JPanel();
			panelItemsReward.setLocation(new IntPoint(13, 47));
			panelItemsReward.setSize(new IntDimension(245, 45));
			panelItemsReward.setPreferredSize(new IntDimension(245, 45));
			var layout5:GridLayout = new GridLayout();
			layout5.setRows(1);
			layout5.setColumns(5);
			layout5.setHgap(5);
			layout5.setVgap(0);
			panelItemsReward.setLayout(layout5);
			
			txtRecord = new JTextArea();
			txtRecord.setLocation(new IntPoint(140, 224));
			txtRecord.setSize(new IntDimension(271, 115));
			txtRecord.setPreferredSize(new IntDimension(271, 115));
			
			panel120 = new JPanel();
			panel120.setLocation(new IntPoint(140, 345));
			panel120.setSize(new IntDimension(271, 24));
			panel120.setPreferredSize(new IntDimension(271, 24));
			var layout6:FlowLayout = new FlowLayout();
			layout6.setAlignment(AsWingConstants.CENTER);
			layout6.setHgap(20);
			layout6.setVgap(0);
			layout6.setMargin(false);
			panel120.setLayout(layout6);
			
			btn_task_give_up = new JButton();
			btn_task_give_up.setLocation(new IntPoint(5, 5));
			btn_task_give_up.setSize(new IntDimension(67, 24));
			btn_task_give_up.setPreferredSize(new IntDimension(67, 24));
			btn_task_give_up.setText("label");
			
			btn_task_complete = new JButton();
			btn_task_complete.setLocation(new IntPoint(41, 5));
			btn_task_complete.setSize(new IntDimension(67, 24));
			btn_task_complete.setPreferredSize(new IntDimension(67, 24));
			btn_task_complete.setText("label");
			
			//component layoution
			getContentPane().append(panel108);
			getContentPane().append(panelItems);
			getContentPane().append(labelGoalInfo);
			getContentPane().append(txtGoal);
			getContentPane().append(panelReward);
			getContentPane().append(txtRecord);
			getContentPane().append(panel120);
			
			panel108.append(panel109);
			
			panel109.append(btn_task_accepted);
			panel109.append(btn_task_acceptable);
			
			panelReward.append(labelRewardInfo);
			panelReward.append(labelEXP);
			panelReward.append(labelMoney);
			panelReward.append(labelWood);
			panelReward.append(labelFood);
			panelReward.append(panelItemsReward);
			
			panel120.append(btn_task_give_up);
			panel120.append(btn_task_complete);
			
			//------------------------------
			panelItemsReward.setClipMasked(false);
			setImages();
			btn_task_give_up.addActionListener(onBtnGiveUp);
		}
		private function onBtnGiveUp(e:Event):void
		{
			//Client.getInstance().sendPacketLogic(1105,[int(_selectedItem.item.task_id)]);
			if(_selectedItem == null)
				return;
			FrameInfo.showMessageDialog("","是否放弃任务 "+_selectedItem.item.task_name+" ?",handleOptionGiveUp,null,true,null,JOptionPane.YES|JOptionPane.NO);
		}
		private function handleOptionGiveUp(button:uint):void
		{
			if(button == JOptionPane.YES)
			{
				//Client.getInstance().sendPacketLogic(1203,[CharInfo.charId]);
				Client.getInstance().sendPacketLogic(1105,[int(_selectedItem.item.task_id)]);
				_selectedItem.selected = false;
				_selectedItem = null;
			}
		}
		private function onBtnComplete(e:Event):void
		{
			
		}
		static public var isAccepted:Boolean = true;
		private function onTabAccepted(e:Event):void
		{
			isAccepted = true;
			if(_selectedItem != null)
			{
				_selectedItem.selected = false;
				_selectedItem = null;
			}
			update();
		}
		private function onBtnAcceptable(e:Event):void
		{
			isAccepted = false;
			if(_selectedItem != null)
			{
				_selectedItem.selected = false;
				_selectedItem = null;
			}
			update();
		}
		private var _arrayItems:Array = new Array;
		private var _arrayItemsReward:Array = new Array;
		public static var _selectedItem:PaneTaskItem = null;
		public function setImages():void
		{
			var img_char_background:DisplayObject = Client.getUIElement("img_task_bg") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_char_background));
			setSizeWH(img_char_background.width,img_char_background.height);
			setLocationXY((Engine.W - width)/2,(Engine.H - height)/2);
			btn_task_accepted.setSelected(true);
			
			
			btn_task_accepted.wrapSimpleButton(Client.getUIElement("btn_task_accepted") as SimpleButton);
			btn_task_acceptable.wrapSimpleButton(Client.getUIElement("btn_task_acceptable") as SimpleButton);
			btn_task_accepted.setText("");
			btn_task_acceptable.setText("");
			
			var group:ButtonGroup = new ButtonGroup();
			group.appendAll(btn_task_accepted,btn_task_acceptable);
			
			btn_task_accepted.addActionListener(onTabAccepted);
			btn_task_acceptable.addActionListener(onBtnAcceptable);
			
			btn_task_give_up.wrapSimpleButton(Client.getUIElement("btn_task_give_up") as SimpleButton);
			btn_task_complete.wrapSimpleButton(Client.getUIElement("btn_task_complete") as SimpleButton);
			btn_task_give_up.setText("");
			btn_task_complete.setText("");
			
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			btn_close.setText("");
			
			txtGoal.setForeground(ASColor.WHITE);
			txtGoal.setEditable(false);
			txtGoal.setWordWrap(true);
			txtGoal.setBackgroundDecorator(null);
			
			txtRecord.setForeground(ASColor.WHITE);
			txtRecord.setEditable(false);
			txtRecord.setWordWrap(true);
			txtRecord.setBackgroundDecorator(null);
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 13, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelEXP.setForeground(ASColor.WHITE);
			labelEXP.setFont(font);
			labelEXP.setTextFilters(new Array(filter));
			labelMoney.setForeground(ASColor.WHITE);
			labelMoney.setFont(font);
			labelMoney.setTextFilters(new Array(filter));
			labelWood.setForeground(ASColor.WHITE);
			labelWood.setFont(font);
			labelWood.setTextFilters(new Array(filter));
			labelFood.setForeground(ASColor.WHITE);
			labelFood.setFont(font);
			labelFood.setTextFilters(new Array(filter));
			
			font = new ASFont("宋体", 13, false, false, false, false);
			labelGoalInfo.setForeground(ASColor.YELLOW);
			labelGoalInfo.setFont(font);
			labelGoalInfo.setTextFilters(new Array(filter));
			labelRewardInfo.setForeground(ASColor.YELLOW);
			labelRewardInfo.setFont(font);
			labelRewardInfo.setTextFilters(new Array(filter));
			
			var i:int = 0;
			for(i = 0; i < 10; i++)
			{
				var btn:PaneTaskItem = new PaneTaskItem();
				panelItems.append(btn);
				_arrayItems[i] = btn;
			}
			
			for(i = 0; i < 5; i++)
			{
				var item:PanelItemCSV = new PanelItemCSV();
				panelItemsReward.append(item);
				_arrayItemsReward[i] = item;
			}
			
			btn_task_complete.setEnabled(false);
			update();
		}
		
		public function update():void
		{
			for each(var paneItem:PaneTaskItem in _arrayItems)
			{
				paneItem.item = null;
			}
			
			for each(var paneItemCSV:PanelItemCSV in _arrayItemsReward)
			{
				paneItemCSV.item = null;
			}
			
			labelEXP.setText("");
			labelMoney.setText("");
			labelWood.setText("");
			labelFood.setText("");
			
			txtGoal.setText("");
			txtRecord.setText("");
			var nIndex:int = 0;

			var array:Array = isAccepted?CharInfo.m_arTasks:getAcceptableTasks();
			if(array.length == 0)
			{
				if(_selectedItem != null)
				{
					_selectedItem.selected = false;
					_selectedItem = null;
				}
			}
			for each(var obj:Object in array)
			{
				if(_arrayItems[nIndex] == null)
					continue;
				(_arrayItems[nIndex] as PaneTaskItem).item = obj;
				
				if(_selectedItem == null)
				{
					_selectedItem = _arrayItems[nIndex];
					_selectedItem.selected = true;
				}
				
				if(_selectedItem == _arrayItems[nIndex])
				{
					_selectedItem.selected = true;
					var objCSVInfo:Object = Client.getInstance().GetTaskCSV(obj.task_id);
					if(objCSVInfo == null)
						return;
					
					if(!FrameTask.isAccepted)
					{
						txtGoal.setHtmlText(obj.name);
						txtRecord.setHtmlText('');
					}
					else
					{
						var textGoal:String = "";
						for each(var objGoal:Object in obj.task_goals)
						{
							textGoal += objGoal.goal_desc+'<br>';
						}
						txtGoal.setHtmlText(textGoal);
						
						if(objCSVInfo.enable_record == 1)
						{
							var text:String = new String;
							text += '<font color="#ffffff">纪录:</font>';
							text += '<font color="#ffff00"> 世界纪录</font>';
							text += '<font color="#ffffff"> (自己)</font>';
							text += '<font color="#00FF00">    ';
							text += PanelMainHelp.formatTime(obj.task_elapsed_time)+'</font><br>';
							if(obj.fastest_char_name != null && obj.fastest_char_name.length > 0)
							{
								text += '<font color="#ffffff">最快:</font><font color="#ffff00"> '+PanelMainHelp.formatTime(obj.fastest_elapsed_time)+'</font>';
								text += '<font color="#ffffff"> ('+PanelMainHelp.formatTime(obj.fastest_self)+')</font>';
								text += '<br> <font color="#999999">['+obj.fastest_char_name;
								text += ' '+obj.fastest_time+']</font>';
								text += '<br>';
							}
							
							if(obj.slowest_char_name != null && obj.slowest_char_name.length > 0)
							{
								text += '<font color="#ffffff">最慢:</font><font color="#ffff00"> '+PanelMainHelp.formatTime(obj.slowest_elapsed_time)+'</font>';
								text += '<font color="#ffffff"> ('+PanelMainHelp.formatTime(obj.slowest_self)+')</font>';
								text += '<br> <font color="#999999">['+obj.slowest_char_name
								text += ' '+obj.slowest_time+']</font>';
								text += '<br>';
							}
							
							if(obj.times_char_name != null && obj.times_char_name.length > 0)
							{
								text += '<font color="#ffffff">最多:</font><font color="#ffff00"> '+obj.times_times+'次</font>';
								text += '<font color="#ffffff"> ('+obj.times_self+'次)</font>';
								text += '<br> <font color="#999999">['+obj.times_char_name;//+'<br>';
								text += ' '+obj.times_time+']</font>';
								text += '<br>';
							}
							txtRecord.setHtmlText(text);
						}
					}
					
					labelEXP.setText(objCSVInfo.reward_exp);
					labelMoney.setText(objCSVInfo.reward_money);
					labelWood.setText(objCSVInfo.reward_wood);
					labelFood.setText(objCSVInfo.reward_food);
					
					var dtemp:Array = (objCSVInfo.reward_items as String).split(';');
					for(var i:int = 0; i < dtemp.length; i++)
					{
						var objItem:Object = Client.getInstance().GetItemCSV(int(dtemp[i]));
						(_arrayItemsReward[i] as PanelItemCSV).item = objItem;
						if(i >= 5)
							break;
					}
				}
				nIndex++;
			}
			btn_task_give_up.setEnabled(_selectedItem != null && _selectedItem.item != null);
			btn_task_give_up.setVisible(isAccepted);
			btn_task_complete.setVisible(isAccepted);
		}
		public static var _frame:FrameTask = null;
		public static function show():void
		{
			if(isShowing())
			{
				hide()
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameTask();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			_frame.update();
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
		
		//public static var _objTaskInfo:Object = new Object;
		public static var _timeTaskUpdate:Timer = null;
		public static function phTask_1100(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phTask_1100", msg);
			var nIndex:uint = 0;
			CharInfo.m_nIdMainCompleted = msg[nIndex++];
			var nCount:uint = msg[nIndex++];
			var array:Array = CharInfo.m_arTasks;
			array.splice(0,array.length);
			for(var i:int = 0; i < nCount; i++)
			{
				var obj:Object = new Object();
				array[i] = obj;
				obj.task_id = msg[nIndex++];
				obj.task_name = msg[nIndex++];
				obj.task_desc = msg[nIndex++];
				obj.task_goals = [];// = msg[nIndex++];
				var nCount1:uint = msg[nIndex++];
				for(var j:int = 0; j < nCount1; j++)
				{
					var objGoal:Object = new Object();
					obj.task_goals[j] = objGoal;
					objGoal.goal_desc = msg[nIndex++];
					objGoal.goal_map_id = msg[nIndex++];
					objGoal.goal_npc_id = msg[nIndex++];
					objGoal.goal_position_map_id = msg[nIndex++];
					objGoal.goal_position_map_x = msg[nIndex++];
					objGoal.goal_position_map_y = msg[nIndex++];
					objGoal.goal_count = msg[nIndex++];
					objGoal.goal_count_size = msg[nIndex++];
				}
				obj.compelte_map_id = msg[nIndex++];
				obj.complete_npc_id = msg[nIndex++];
				obj.task_elapsed_time = msg[nIndex++];
				obj.task_step = msg[nIndex++];
				obj.task_step_size = msg[nIndex++];
				
				//obj.task_update_record = msg[nIndex++];
			}
			
			PanelMainHelp.getInstance().updateTasks();
			if(_timeTaskUpdate == null)
			{
				_timeTaskUpdate = new Timer(1000);
				_timeTaskUpdate.addEventListener(TimerEvent.TIMER,onTimerUpdateTaskInfo);
			}
			if(!_timeTaskUpdate.running)
				_timeTaskUpdate.start();
			if(isShowing())
				_frame.update();
			SceneMain.updateNpcTaskEffect();
		}
		public static function getTaskInfo(task_id:int):Object
		{
			for each(var obj:Object in CharInfo.m_arTasks)
			{
				if(obj.task_id == task_id)
					return obj;
			}
			return null;
		}
		public static function phTaskRecordUpdate_1102(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phTaskRecordUpdate_1102", msg);
			var nIndex:uint = 0;
			
			var task_id:uint = msg[nIndex++];
			var obj:Object = getTaskInfo(task_id);
			
			if(obj == null)
				return;
			
			obj.fastest_char_id = msg[nIndex++];
			obj.fastest_char_name = msg[nIndex++];
			obj.fastest_elapsed_time = msg[nIndex++];
			obj.fastest_time = msg[nIndex++];
			obj.fastest_self = msg[nIndex++];
			
			obj.slowest_char_id = msg[nIndex++];
			obj.slowest_char_name = msg[nIndex++];
			obj.slowest_elapsed_time = msg[nIndex++];
			obj.slowest_time = msg[nIndex++];
			obj.slowest_self = msg[nIndex++];
			
			obj.times_char_id = msg[nIndex++];
			obj.times_char_name = msg[nIndex++];
			obj.times_times = msg[nIndex++];
			obj.times_time = msg[nIndex++];
			obj.times_self = msg[nIndex++];
			
			//PanelMainHelp.getInstance().updateTaskInfo();
			if(isShowing())
				_frame.update();
		}
		public static var _task_info_acceptable:String = new String;
		public static function phTaskAcceptable_1104(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phTaskAcceptable_1104", msg);
			var nIndex:uint = 0;
			
			_task_info_acceptable = msg[nIndex++];
			
			PanelMainHelp.getInstance().updateTasks(false);
			if(isShowing())
				_frame.update();
		}
		public static var _arCountEveryday:Array = [];
		public static function phTaskCountEveryday_1106(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phTaskCountEveryday_1106", msg);
			var nIndex:uint = 0;
			
			var nCount:uint = msg[nIndex++];
			var array:Array = _arCountEveryday;
			array.splice(0,array.length);
			for(var i:int = 0; i < nCount; i++)
			{
				var obj:Object = new Object();
				//array[i] = obj;
				obj.task_id = msg[nIndex++];
				array[obj.task_id] = obj;
				obj.count_everyday = msg[nIndex++];
			}
		}
		public static function onTimerUpdateTaskInfo(e:TimerEvent):void
		{
			for each(var obj:Object in CharInfo.m_arTasks)
			{
				obj.task_elapsed_time++;
			}
			if(CharInfo.m_arTasks.length == 0)
				_timeTaskUpdate.stop();
			//_objTaskInfo.task_elapsed_time++;
			PanelMainHelp.getInstance().updateTasks(false);
			if(isShowing())
				_frame.update();
		}
		public static function isAcceptedMain():Boolean
		{
			for each(var obj:Object in CharInfo.m_arTasks)
			{
				var objCSVInfo:Object = Client.getInstance().GetTaskCSV(obj.task_id);
				if(objCSVInfo == null)
					continue;
				if(objCSVInfo.type == Const.TASK_TYPE_MAIN)
					return true;
			}
			return false;
		}
		public static function getAcceptableTasks():Array
		{
			//obj.csv_id = csv.data[i][nIndex++];
			//obj.type = csv.data[i][nIndex++];
			//obj.name = csv.data[i][nIndex++];
			//obj.description = csv.data[i][nIndex++];
			//obj.enable_record = csv.data[i][nIndex++];
			//obj.enable_double = csv.data[i][nIndex++];
			//obj.require_level = csv.data[i][nIndex++];
			var array:Array = [];
			var nCount:int = 0;
			var acceptedMain:Boolean = isAcceptedMain();
			var bAddedMain:Boolean = false;
			for each(var obj:Object in Client._TaskCSV)
			{
				if(obj.require_level >= CharInfo.m_nLevel - 10 && obj.require_level <= CharInfo.m_nLevel + 10)
				{
					if(obj.type == Const.TASK_TYPE_MAIN)
					{
						if(bAddedMain || acceptedMain || obj.csv_id <= CharInfo.m_nIdMainCompleted)
						{
							continue;
						}
						bAddedMain = true;
					}
					
					array.push(obj);
					nCount++;
					if(nCount >= 10)
						break;
					
				}
			}
			return array;
		}
	}
}

import com.*;
import com.Engine.*;
import com.Packet.*;
import com.UI.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

//import mx.containers.Panel;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;
import org.aswing.tree.AbstractLayoutCache;

/**
 * MyPaneFriendItem
 */
class PaneTaskItem extends JPanel{
	
	//members define
	public var labelText:JLabel;
	private var panelType:JPanel;
	
	/**
	 * MyPaneFriendItem Constructor
	 */
	public function PaneTaskItem(){
		//component creation
		setSize(new IntDimension(129, 20));
		setPreferredSize(new IntDimension(129, 20));
		var layout0:EmptyLayout = new EmptyLayout();
		setLayout(layout0);
		
		labelText = new JLabel();
		labelText.setLocation(new IntPoint(20, 0));
		labelText.setSize(new IntDimension(109, 18));
		labelText.setPreferredSize(new IntDimension(109, 18));
		labelText.setText("label");
		labelText.setHorizontalAlignment(AsWingConstants.LEFT);
		
		panelType = new JPanel();
		panelType.setLocation(new IntPoint(0, 0));
		panelType.setSize(new IntDimension(20, 20));
		panelType.setPreferredSize(new IntDimension(20, 20));
		
		//component layoution
		append(labelText);
		append(panelType);
		
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 13, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 10);
		labelText.setForeground(ASColor.WHITE);
		labelText.setFont(font);
		labelText.setTextFilters( new Array(filter));
		
		addEventListener(MouseEvent.ROLL_OVER, onRollOver);
		addEventListener(MouseEvent.ROLL_OUT, onRollOut);
		addEventListener(MouseEvent.CLICK, onClick);
		
		img_background = null;//new AssetBackground(Client.getUIElement("img_task_item") as DisplayObject);
		img_background_select = new AssetBackground(Client.getUIElement("img_task_item_select") as DisplayObject)
		labelText.setBackgroundDecorator(img_background);
		
	}
	private var img_background:AssetBackground = null;
	private var img_background_select:AssetBackground = null;
	private function onRollOver(event:MouseEvent):void
	{
		if(_item == null)return;
		
		if(labelText.getBackgroundDecorator() != img_background_select)
		{
			labelText.setBackgroundDecorator(img_background_select);
		}
	}
	
	private function onRollOut(event:MouseEvent):void
	{
		if(_item == null)return;
		selected = _selected;
	}

	private function onClick(event:MouseEvent):void
	{
		if(_item == null)return;
		if(FrameTask._selectedItem != null)
		{
			FrameTask._selectedItem.selected = false;
			FrameTask._selectedItem = null;
		}
		selected = true;
		FrameTask._selectedItem = this;
		FrameTask._frame.update();
	}
	
	private var _selected:Boolean = false;
	public function set selected(val:Boolean):void
	{
		_selected = val;
		if(_selected && labelText.getBackgroundDecorator() != img_background_select)
		{
			labelText.setBackgroundDecorator(img_background_select);
		}
		
		if(!_selected && labelText.getBackgroundDecorator() != img_background)
		{
			labelText.setBackgroundDecorator(img_background);
		}
	}
	
	private var _item:Object = null;
	public function set item(val:Object):void
	{
		_item = val;
		labelText.setText("");
		panelType.setBackgroundDecorator(null);
		if(_item == null)
		{
			//selected = false;
			return;
		}
		var objCSVInfo:Object = _item;
		if(FrameTask.isAccepted)
		{
			objCSVInfo = Client.getInstance().GetTaskCSV(_item.task_id);
			if(objCSVInfo == null)
				return;
		}
		if(objCSVInfo.require_level > CharInfo.m_nLevel)
			labelText.setForeground(ASColor.RED);
		else
			labelText.setForeground(ASColor.WHITE);
		labelText.setText('['+objCSVInfo.require_level+']'+objCSVInfo.name);
		//selected = _selected;
		if(objCSVInfo.type == 0)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_0") as DisplayObject));
		if(objCSVInfo.type == 1)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_1") as DisplayObject));
		if(objCSVInfo.type == 2)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_2") as DisplayObject));
		if(objCSVInfo.type == 3)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_3") as DisplayObject));
		if(objCSVInfo.type == 4)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_4") as DisplayObject));
		pack();
		this.paintImmediately();
		
	}
	public function get item():Object
	{
		return _item;
	}
	public function clear():void
	{
		labelText.setBackgroundDecorator(null);

	}
	//_________getters_________
	
}